<?php session_start(); ?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<? 

	include "connect.php";
	$sql="SELECT * FROM email_send order by id";
	$rs=mysql_db_query($dbname,$sql);
	
	### FUNCTION SEND MAIL ####
	include ("class.phpmailer.php");
	function scriptdd_sendmail($to_name,$to_email,$from_name,$email_user_send,$email_pass_send,$subject,$body_html,$body_text) {
		
		$mail = new PHPMailer();
		$mail->CharSet = "utf-8";
		$mail -> From     = $email_user_send;
		$mail -> FromName = $from_name;
		include "connect.php";
		$sql="SELECT * FROM email_send order by id";
		$rs=mysql_db_query($dbname,$sql);
		while($rss=mysql_fetch_array($rs)){
		$to_email=$rss[email];
			$mail -> AddAddress($to_email,$to_name);
		}
		$mail -> Subject	= $subject;
		$mail -> Body		= $body_html;
		
		$mail -> IsHTML (true);
		
		$mail->IsSMTP();
		$mail->Host = 'ssl://smtp.gmail.com';
		$mail->Port = 465;
		$mail->SMTPAuth		= true;
		//$mail->SMTPDebug	= true;
		$mail->Username = $email_user_send;
		$mail->Password = $email_pass_send;
		
		$mail->Send();
		$mail->ClearAddresses();
		
		
		return $result;
	
	}
if($_POST[action]=="send"){
	if($_SESSION['security_code'] <> $_POST['font'] or $_POST[font]==""){
		echo "<script>alert('invalid security code');history.back();</script>";
		exit();
	}
	$type = $_POST[type];
	$mailsubject=$_POST[name];
	$mailfrom=$_POST[email];
	$tel=$_POST[tel];
	$address=$_POST[address];
	$age=$_POST[age];
	$detail=$_POST[detail];
	$gender = $_POST[gender];
	$option = implode(",",$_POST[option]);
	
	$to_name ="";
	$from_name	="Fitforward Inquiry";
	$email_user_send ="system.fitforward@gmail.com";
	$email_pass_send ="conceptplays";
	$body_text	="";
	
	if($type==1){
		$subject ="ต้องการติดต่อสอบถามจากคุณ".$mailsubject;
		$body_html ="
		รายละเอียดอื่นๆ ::".$detail." <br>     
		เบอร์โทรติดต่อ  ::  ".$tel."<br>
		Emailติดต่อ ::  ".$mailfrom."<br>
		
		";
	}else {
		$subject = "ต้องการติดต่อสมัครสมาชิกจากคุณ".$mailsubject;
		$body_html ="
		ชื่อ::".$mailsubject." <br>
		อายุ ::".$age." <br>
		เพศ ::".$gender."<br>
		สิ่งที่คาดหวังต่อการใช้บริการจากฟิตเนส ::".$option."<br>
		รายละเอียดอื่นๆ ::".$detail." <br>     
		เบอร์โทรติดต่อ  ::  ".$tel."<br>
		รายละเอียดที่อยู่ :: ".$address."<br>
		Emailติดต่อ ::  ".$mailfrom."<br>";
	}
	scriptdd_sendmail($to_name,$to_email,$from_name,$email_user_send,$email_pass_send,$subject,$body_html,$body_text);
	
} 
 
?>
<SCRIPT LANGUAGE="JavaScript">alert("ส่งเมลเรียบร้อยแล้ว ค่ะ");window.location='index.html';</script>
<style type="text/css">
<!--
.aceTextField2 {background-color: #695237;
border-width: 0;
}
.style3 {	color: #ae9a82;
	font-size: 16px;
	font-family: Arial, Helvetica, sans-serif;
}
-->
</style>
